#include "BulletHandler.h"
#include <iostream>


BulletHandler::BulletHandler(){}
BulletHandler::~BulletHandler(){}


void BulletHandler::initialize()
{
	m_image = new sf::Texture();
	m_image->loadFromFile("bilder/Player/bullet2.png");
}

void BulletHandler::addBullet(sf::RenderWindow* m_renderWindow, float angle, sf::Vector2f playerPos)
{
	bullets* bulletObj = new bullets;
	bulletObj->initialize(m_renderWindow, angle, playerPos, m_image);
	bulletArray.push_back(bulletObj);
}

void BulletHandler::update()
{
	for(int i = 0; i < bulletArray.size(); i++)
	{
		bulletArray[i]->update();

		if(bulletArray[i]->m_bulletSprite->getPosition().x < 0 || 
			bulletArray[i]->m_bulletSprite->getPosition().x > 2560 ||
			bulletArray[i]->m_bulletSprite->getPosition().y < 0 ||
			bulletArray[i]->m_bulletSprite->getPosition().y > 1440)
		{
			bulletArray[i]->cleanup();
			delete bulletArray[i];
			bulletArray.erase (bulletArray.begin()+i);
		}
	}

}

void BulletHandler::cleanup()
{

}
